//
//  BaseInformationViewController.m
//  BeanTrip
//
//  Created by dlios on 15-7-9.
//  Copyright (c) 2015年 PandaGroup. All rights reserved.
//

#import "BaseInformationViewController.h"
#import "HTTPTool.h"
#import "BaseInformationTableViewCell.h"
#define WIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define HEIGH ([UIScreen mainScreen].bounds.size.height/667)
@interface BaseInformationViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic, retain)UILabel *informationLabel;
@property(nonatomic, retain)UILabel *contentLabel;
@property(nonatomic, retain)UILabel *addressLabel;
@property(nonatomic, retain)UILabel *addressContent;

@property(nonatomic, retain)UITableView *informationTable;
@end

@implementation BaseInformationViewController
- (void)dealloc
{
    [_informationLabel release];
    [_contentStr release];
    [_contentLabel release];
    [_addressStr release];
    [_addressLabel release];
    [_addressContent release];
    [_informationTable release];
    [_getTitleValue release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationController.navigationBar.translucent = NO;
    self.title = self.getTitleValue;
    self.informationLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 10*HEIGH, 375*WIDTH-20*WIDTH, 50*HEIGH)];
    self.informationLabel.text = @"基本信息";
    self.informationLabel.font = [UIFont systemFontOfSize:25];
    self.informationLabel.textAlignment=NSTextAlignmentCenter;
    self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 60*HEIGH, 375*WIDTH-20*WIDTH, 30*HEIGH)];

    self.addressLabel.text = @"地址";
    self.addressLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];
    self.addressContent = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 90*HEIGH, 375*WIDTH-20*WIDTH, 50*HEIGH)];
    self.addressContent.text = self.addressStr;
    self.addressContent.numberOfLines = 0;
    self.addressContent.font = [UIFont systemFontOfSize:14];
    self.addressContent.numberOfLines = 0;
    self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10*WIDTH, 140*HEIGH, 375*WIDTH-20*WIDTH, 20*HEIGH)];
    self.contentLabel.text = @"概括";
    
    self.contentLabel.font = [UIFont fontWithName:@"Helvetica-BoldOblique" size:20];
  
    /**
     创建一个tableView
     
     :returns: return value description
     */
    self.informationTable=[[UITableView alloc] initWithFrame:CGRectMake(10*WIDTH, 160*HEIGH, 375*WIDTH-20*WIDTH, 667*HEIGH) style:UITableViewStyleGrouped];
    /**
     *  设置tableView的背景颜色
     */
    self.informationTable.backgroundColor=[UIColor whiteColor];
    /**
     *  把tableView添加到view上
     */
    [self.view addSubview:self.informationTable];
    /**
     *  设置代理人
     */
    self.informationTable.dataSource=self;
    self.informationTable.delegate=self;
    /**
     *  6.内存释放
     */
    [self.informationTable release];
    
    [self.view addSubview:self.informationLabel];
    [self.view addSubview:self.addressLabel];
    [self.view addSubview:self.addressContent];
    [self.view addSubview:self.contentLabel];
    
    [self.informationLabel release];
    [self.addressLabel release];
    [self.addressContent release];
    [self.contentLabel release];
}





-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
/**
 * 8.第二个协议方法  返回值只有一个
 *
 *  @param tableView
 *  @param indexPath
 *
 *  @return cell
 */
-(BaseInformationTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *reuse=@"reuse";
    BaseInformationTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell=[[[BaseInformationTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse] autorelease];
    }
    
    cell.baseLabel.text = self.contentStr;
    cell.backgroundColor=[UIColor whiteColor];

    /**
     * 动画效果
     */
    cell.layer.transform = CATransform3DMakeScale(0.3, 0.3, 0.1);
    [UIView animateWithDuration:0.5 animations:^{
        
        cell.layer.transform = CATransform3DMakeScale(1, 1, 0.1);
    }];
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    /**
     *  计算文字的高度(文字自适应)
     *
     */
    NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14],NSFontAttributeName, nil];
    /**
     *  根据文本来计算高度,首先限制一个文本的最大范围(375,0)苹果6
     *  第二个属性作用:指定一个属性来定义对应文本和字体所占用的高度.
     */
    
    CGRect rect=[self.contentStr boundingRectWithSize:CGSizeMake(375*WIDTH, 0) options: NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height*1.2;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
